package com.mdxq.springboot04_mybatis_plus.controller;

import com.mdxq.springboot04_mybatis_plus.entity.Tea;
import com.mdxq.springboot04_mybatis_plus.service.TeaService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author WanJl
 * @version 1.0
 * @title TeaController
 * @description
 * @create 2024/11/18
 */
@RestController
public class TeaController {

    @Resource
    private TeaService teaService;

    @RequestMapping("/tea/queryAll")
    public List<Tea> queryAll() {
        List<Tea> teaList = teaService.queryAll();
        return teaList;
    }

    @RequestMapping("/tea/save")
    public String save(@RequestBody Tea tea) {
        Integer i = teaService.saveTea(tea);
        return "新增"+i+"条茶叶信息";
    }

    @RequestMapping("/tea/edit")
    public String edit(@RequestBody Tea tea) {
        Integer i = teaService.edit(tea);
        return "修改"+i+"条茶叶信息";
    }

    @RequestMapping("/tea/remove")
    public String remove(Integer id) {
        Integer i = teaService.remove(id);
        return "删除"+i+"条茶叶信息";
    }

    @RequestMapping("/tea/queryOne")
    public Tea queryOne(Integer id) {
        return teaService.queryById(id);
    }
}

// S(spring)S(structs2)H(hibernate)
//          ||
// S(spring)S(springMV)M(Mybatis)
//          ||
// Springboot(spring+springMV)+Mybatis(mybatis-plus)
//
// SpringJPA(spring提供的持久层框架)
// Spring全家桶